from multiprocessing import Process
import os
import time

def task_process(delay):
    num = 0
    for i in range(delay*10000000):
        num += i
    print(f'进程pid为{os.getpid()},进程完成')

if __name__ == '__main__':
    print('父进程id为%s'%os.getpid())
    t0 = time.time()
    task_process(4)
    task_process(4)
    t1 = time.time()
    print(f'顺序同步方式执行耗时{t1-t0}')

    p0 = Process(target=task_process,args = (4,))
    p1 = Process(target=task_process, args=(4,))
    t2 = time.time()
    p0.start();p1.start()
    p0.join();p1.join()
    t3 = time.time()
    print(f'多进程异步执行耗时{t3-t2}')